package models;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;

import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;

import objects.ConceptList;
import objects.Ontology;

/* Reads from and Writes to XML files */
public class OntologyModel {
	
	/* static ontology variable to remove need for creating OntologyModel objects */
	private static ArrayList<ConceptList> ontology;
	
	public OntologyModel() {}
	
	public static void read() throws ParserConfigurationException, SAXException, IOException {
		OntologyXMLReader reader = new OntologyXMLReader();
		reader.read("src/xml/Ontology/ontology.xml");
		ontology = reader.getDatabase();
	}
	
	/* Currently not in use */
	public static void write() throws FileNotFoundException, IOException {
		Ontology db = new Ontology();
		db.setOntologyList(ontology);
		
		OntologyXMLWriter writer = new OntologyXMLWriter();
		writer.setDatabase(db);
		writer.write("src/xml/Ontology/ontology.xml");
	}
	
	/** Get/Set data **/
	
	public static void setOntology(ArrayList<ConceptList> newOntology) {
		ontology = newOntology;
	}
	
	public static ArrayList<ConceptList> getOntology() {
		return ontology;
	}
}
